package com.globalresources.dao.hibernate;

import java.util.List;

import com.globalresources.commons.StringHelper;
import com.globalresources.dao.inface.IAuthorityDao;
import com.globalresources.po.Authority;
import com.trg.dao.dao.standard.GenericDAOImpl;
import com.trg.search.Search;

/**
 * @author aaron.lu(luzhiyuan) E-mail:atyuan.lu@gmail.com
 * @since 创建时间：Jul 7, 2009 3:13:31 AM
 */
public class AuthorityDaoHibernate extends GenericDAOImpl<Authority, Integer> implements IAuthorityDao{
	
		/**
		 * load authority
		*@author aaron.lu(luzhiyuan)
		*@param authority
		*@param pagesize
		*@param startrow
		*@return
		 */
		public List<Authority> getAuthorities(String authority, int pagesize, int startrow){
			Search search = new Search();
			search.setFirstResult(startrow);
			search.setMaxResults(pagesize);
			if (StringHelper.isNotEmpty(authority)) {
				search.addFilterLike("authority", "%"+authority+"%");
			}
			return super.search(search);
		}
		
		/**
		 * count the authority
		*@author aaron.lu(luzhiyuan)
		*@param authority
		*@return
		 */
		public int count(String authority){
			Search search = new Search();
			if (StringHelper.isNotEmpty(authority)) {
				search.addFilterLike("authority", "%"+authority+"%");
			}
			return search(search).size();
		}
	
}
